package com.game.web.gateway.common;

import com.game.framework.common.error.GameException;
import com.game.framework.common.error.IServerErrorCode;
import org.slf4j.helpers.MessageFormatter;

public enum WebGatewayServerErrorCodeCode implements IServerErrorCode {
    UNKNOWN(-2, "网关服务器未知道异常")
    ;
    private int errorCode;
    private String errorMessage;


    WebGatewayServerErrorCodeCode(int errorCode, String errorMessage) {
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    @Override
    public int getErrorCode() {
        return errorCode;
    }

    @Override
    public String getErrorMessage() {
        return errorMessage;
    }

    @Override
    public GameException newException() {
        String errorMsg = "errorCode:" + this.errorCode + "," + this.errorMessage;
        return new GameException(this, errorMsg);
    }

    public GameException newException(String format, Object... args) {
        if (args != null) {
            format = MessageFormatter.arrayFormat(format, args).getMessage();
        } else {
            format = "";
        }
        String errorMsg = "errorCode:" + this.errorCode + "," + this.errorMessage + "," + format;
        return new GameException(this, errorMsg);
    }

    @Override
    public String toString() {
        return "WebGatewayServerErrorCodeCode{" +
                "errorCode=" + errorCode +
                ", errorDesc='" + errorMessage + '\'' +
                '}';
    }
}
